#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,k,s[100005];
struct node{
	int h[1<<4];
	int tag[4];
	node(){}
}tree[800005];
void upxg(node& tr){
	for(int x=0;x<4;x++){
		if(!tr.tag[x])continue;
		for(int y=0;y<(1<<4);y++){
			int uv=tr.h[y];
			tr.h[y]=0;
			tr.h[y|(1<<x)]+=uv;
		}
	}
}
node merge(const node& a,const node& b,vector<int> tag){
	node re;
	for(int i=0;i<4;i++)re.tag[i]=tag[i];
	bool ok=0;
	for(int j=0;j<(1<<4);j++)re.h[j]=a.h[j]+b.h[j],ok=ok||re.h[j];
	if(!ok)re.h[0]=1;
	upxg(re);
	return re;
}
void xg(int i,int l,int r,int tl,int tr,int v,int cnt){
	if(l<=tl&&tr<=r){
		tree[i].tag[v-1]+=cnt;
		tree[i]=merge(tree[i<<1],tree[i<<1|1],vector<int>(tree[i].tag,tree[i].tag+4));
		return;
	}
	int mid=(tl+tr)>>1;
	if(l<=mid)xg(i<<1,l,r,tl,mid,v,cnt);
	if(r>mid)xg(i<<1|1,l,r,mid+1,tr,v,cnt);
	tree[i]=merge(tree[i<<1],tree[i<<1|1],vector<int>(tree[i].tag,tree[i].tag+4));
}
vector<int> tagsum(4,0);
node getans(int i,int l,int r,int tl,int tr){
	node re;
	if(l<=tl&&tr<=r){
		re=tree[i];
		for(int j=0;j<4;j++)re.tag[j]=tagsum[j];
		upxg(re);
		return re;
	}
	int mid=(tl+tr)>>1;
	for(int x=0;x<4;x++)tagsum[x]+=tree[i].tag[x];
	if(l<=mid&&r>mid)re=merge(getans(i<<1,l,r,tl,mid),getans(i<<1|1,l,r,mid+1,tr),vector<int>(4,0));
	else if(l<=mid)re=getans(i<<1,l,r,tl,mid);
	else re=getans(i<<1|1,l,r,mid+1,tr);
	for(int x=0;x<4;x++)tagsum[x]-=tree[i].tag[x];
	return re;
}
map<int,int[5]> mp;
void build(int i,int l,int r){
	tree[i].h[0]=r-l+1;
	if(l==r)return;
	int mid=(l+r)>>1;
	build(i<<1,l,mid);
	build(i<<1|1,mid+1,r);
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
  	freopen("reporter.in","r",stdin);
  	freopen("reporter.out","w",stdout);
	cin>>n>>k;
	build(1,1,n);
	ll ans=0;
	for(int i=1;i<=n;i++){
		cin>>s[i];
		for(int j=0;j+1<5;j++){
			if(mp[s[i]][j])xg(1,mp[s[i]][j+1]+1,mp[s[i]][j],1,n,j+1,-1);
			else break;
		}
		for(int j=4;j;j--)mp[s[i]][j]=mp[s[i]][j-1];
		mp[s[i]][0]=i;
		for(int j=0;j+1<5;j++){
			if(mp[s[i]][j])xg(1,mp[s[i]][j+1]+1,mp[s[i]][j],1,n,j+1,1);
			else break;
		}
		vector<int> v(getans(1,1,i,1,n).h,getans(1,1,i,1,n).h+(1<<4));
		for(int j=0;j<(1<<4);j++)if((j&((1<<k)-1))==(1<<k)-1)ans+=v[j];
	}
	cout<<ans;
}
